<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<link rel="stylesheet" href="/layui/css/layui.css">
<style rel="stylesheet" type="text/css">
    .index-page {
        padding: 10px 20px 0;
    }
</style>
<!-- 载入文章头部页面，位置在/client文件夹下的header模板页面，模板名称th:fragment为header -->
<div th:replace="/client/header::header(null,null)"/>


<body style="background-color: #f2dede">

<div class="am-g am-g-fixed blog-fixed index-page" style="background-color: whitesmoke">
    <div class="am-g am-g-fixed blog-fixed index-page" style="background-color: whitesmoke">
        <h1 style="color: #2e6da4">我的课程</h1>
        <a th:if="${session.user.getType()}=='老师'" th:href="@{/teacher/createCourse}">创建课程</a>
        <hr style="height: 5px;background-color:pink"/>
        <div class="am-input-group am-input-group-sm">
            <input name="search" class="am-form-field" id="search" style="border-radius: 8px 0px 0px 8px;"
                   onclick="showHistory(getData('searchHistory'))" type="text" placeholder="输入班级、校区或者标签试一试"
                   autocomplete="off">
            <span class="am-input-group-btn">
        <button class="am-btn am-btn-default" id="search-button"
                onclick="saveSearch('searchHistory', $('#search').val())" type="submit">搜索</button>
    </span>
        </div>
        <div class="am-u-md-8 am-u-sm-12">
            <!-- 课程遍历并分页展示 -->
            <div th:each="course: ${session.courseListById.list}">
                <article class="am-g blog-entry-article">
                    <div class="am-u-lg-6 am-u-md-12 am-u-sm-12 blog-entry-img">
                        <img width="100%" class="am-u-sm-12" th:src="@{/user/img/apple-touch-icon.png}"
                             style="width: 200px;height: 200px"/>
                    </div>
                    <div class="am-u-lg-6 am-u-md-12 am-u-sm-12 blog-entry-text">
                        <!-- 文章分类 -->
                        <span class="blog-color" style="font-size: 15px;"><a th:text="'课程名称:'+${course.course_name}"></a></span>
                        <span>&nbsp;&nbsp;&nbsp;</span>
                        <!-- 发布时间 -->
                        <span style="font-size: 15px;" th:text="'发布于 '+ ${commons.dateFormat(course.created)}"/>
                        <h2>
                            <div><a style="color: #0f9ae0;font-size: 20px;" th:href="@{'/user/courseDetails/'+${course.id}}"
                                    th:text="${course.course_name}"/>
                            </div>
                        </h2>
                        <!-- 课程描述-->
                        <a>
                            <div style="font-size: 16px;" th:utext="${commons.introCourse(course,15)}"/>
                        </a>
                    </div>
                </article>
            </div>
            <!-- 文章分页信息 -->
            <div class="am-pagination">
                <div th:replace="/comm/paging::pageUser(${session.courseListById},'上一页','下一页','user/Course',${session.user.getId()})"/>
            </div>
        </div>
    </div>
</body>

<script>
    function delArticle(id) {

        var user_id = $("#user_id").val();
        $.post("/user/deleteArticle",
            {
                id: id
            },
            function (data) {

                if (data == "OK") {
                    alert("删除成功！");
                    window.location.href = '/userArticles/' + '1/' + user_id;
                }
                else {
                    alert("删除失败！");
                    window.location.reload();
                }
            }
        )
    }
</script>
<!-- 载入文章尾部页面，位置在/client文件夹下的footer模板页面，模板名称th:fragment为footer -->
<div th:replace="/client/footer::footer"/>
</html>
